home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_11_05 / test_obj / dgen.syn < prev    next >
Text File  |  1993-01-20  |  8KB  |  236 lines

  1. /* File:     DGEN.SYN
  2.    Copyright Norman Wilde 1993
  3.    Notes:    Contains Anagram syntax for a test driver generator that
  4.              handles input data for some of the basic types of C, that is:
  5.                   char
  6.                   string  (ie. char * with nul termination)
  7.                   int
  8.                   double
  9.                   FILE *
  10.              as well as for the objects in the Invoice example:
  11.                   Item
  12.                   Client
  13.                   Invoice
  14.              Array inputs are tricky since the compiler generally needs
  15.              to know the dimension of the array to be able to interpret
  16.              an initializer. One way around this is to 'typedef' an array
  17.              of the desired size. As illustration, we include the following
  18.              type:
  19.           intarr2 (array of 2 ints - typedef as INTARR2)
  20.              Users will normally add to this list any other types or
  21.              object classes used in the code they plan to test. Just add
  22.              another alternative to the 'declaration' production below.
  23.              
  24.              When AnaGram processes this file, it will produce a C program
  25.              called DGEN.C
  26.              that reads test specification files and writes test driver
  27.              programs. Compile DGEN.C and link with TUTILS.C to produce
  28.              DGEN.EXE.
  29.  
  30.              See the README.TXT file for further explanations of the
  31.              testing system in general. See TUTILS.H for descriptions
  32.              of the functions used in the reduction procedures. See
  33.              T001.TST for an example of a test specification file
  34.              that is described by this grammar. See T001.CPP for an
  35.              example of a generated test driver created by running
  36.              DGEN.EXE.
  37. */
  38. {
  39. #include "tutils.h"
  40. }
  41. // AnaGram configuration parameter settings
  42. [
  43.   ~allow macros
  44. ]
  45. // Basic syntax stuff
  46.  
  47. alpha = 'a-z' + 'A-Z' + '_'
  48. digit = '0-9'
  49. alphanumeric = alpha + digit
  50. doubleQuote = '\"'
  51. eof = -1 + 0 + ^D + ^Z
  52. blank = ' ' + '\t'
  53. eol = '\n'
  54. stringCharacter = ~(eof + '"' + eol)
  55. blockCharacter = ~(eof + '{' + '}')
  56. commentCharacter = ~(eof + eol)
  57. notCloseBracket = ~(']')
  58. space
  59.   -> blank | eol | comment
  60. comment
  61.  -> "//", commentCharacter?..., eol
  62. (char *)variable
  63.   -> varStart, varRest?                 =release();
  64. varStart
  65.   -> alpha:c                            =collectFirst(c);
  66. varRest
  67.   -> alphanumeric:c                     =collect(c);
  68.   -> varRest, alphanumeric:c            =collect(c);
  69. (char*) string
  70.    -> doubleQuote, stringContents,
  71.       doubleQuote                            =release();
  72. stringContents
  73.   -> stringCharacter:c                  =collectFirst(c);
  74.   -> stringContents,
  75.      stringCharacter:c                  =collect(c);
  76. // The following is a simplified C
  77. // language block, any '{' and '}'
  78. // must balance, even in strings or
  79. // comments
  80. (char *) block
  81.   -> blockStart,
  82.      blockComponent?...,
  83.      '}'                                ={collect('}');return(release());}
  84. blockStart
  85.   -> '{'                                =collectFirst('{');
  86. blockComponent
  87.   -> blockCharacter:c                   =collect(c);
  88.   -> nestedBlock
  89. nestedBlock
  90.   -> nestStart, blockComponent?...,
  91.      '}'                                =collect('}');
  92. nestStart
  93.   -> '{'                                =collect('{');
  94. (struct STRLIST *) initializerList
  95.   -> initializer:s                      =listNew(s,"");
  96.   -> initializerList:lst, initializer:s =listAdd(lst,s,"");
  97. (char *) initializer
  98.   -> '[', initializer contents, ']',
  99.      space?...                          =release();
  100. initializer contents
  101.   -> notCloseBracket:c                  =collectFirst(c);
  102.   -> initializer contents,
  103.      notCloseBracket:c                  =collect(c);
  104.  
  105. // GRAMMAR FOR A TEST SPECIFICATION FILE
  106. grammar
  107.  ->  space?..., statement..., eof       =writeDriver();
  108.  
  109. statement
  110.  -> embeddedBlock, space?...
  111.  -> runStatement, space?...
  112.  -> declaration, space?...
  113.  
  114. // a block of C code to be copied into the generated test driver
  115. embeddedBlock
  116.  -> block:eb                            =addBlock(eb);
  117.  
  118. // a runStatement describes a set of tests to be run. The driver
  119. // main loop will choose one combination of the values of the
  120. // variables in the variableList and will use that set of values
  121. // to execute the block of c/c++ code. If the keyword in the
  122. // testSpec is "combining", the main loop will generate all
  123. // combinations of the possible values of the variables. If
  124. // the keyword in the testSpec is "varying", each of the variables
  125. // will be varied one by one, with the other variables held
  126. // at their default value (ie, the first value in the declaration).
  127. runStatement
  128.   -> runHeader, space..., testSpec
  129. runHeader
  130.   -> "runtest", space..., string:n      =setRunName(n);
  131. testSpec
  132.   -> "varying", space...,
  133.      variableList:vl, block:b           =makeVary(vl,b);
  134.   -> "combining", space...,
  135.      variableList:vl, block:b           =makeComb(vl,b);
  136. (struct STRLIST *) variableList
  137.   -> variable:v, space...               =listNew(v,"");
  138.   -> variableList:lst, variable:v,
  139.      space...                           =listAdd(lst,v,"");
  140.  
  141. // Syntax for declarations of set variables. Each variable
  142. // represents a set of objects; the members of the set
  143. // are given by the initializers in the declaration.
  144. declaration
  145.  -> charDeclaration
  146.  -> stringDeclaration
  147.  -> intDeclaration
  148.  -> doubleDeclaration
  149.  -> FILEDeclaration
  150.  -> intarr2Declaration
  151.  -> ItemDeclaration
  152.  -> ClientDeclaration
  153.  -> InvoiceDeclaration
  154. // add others as needed
  155.  
  156. // Declaration of a set of chars
  157. charDeclaration
  158.   -> "char", space...,
  159.       variableList:vl, "{", space?...,
  160.       initializerList:il, "}"           =addTVars(vl,"char","char",il);
  161. // the initializers should be single
  162. // characters, eg:
  163. //   ['A'] [ '\n' ] ['\0']
  164.  
  165. // Declaration of a set of strings
  166. stringDeclaration
  167.   -> "string", space...,
  168.       variableList:vl, "{", space?...,
  169.       initializerList:il, "}"           =addTVars(vl,"char *","char *",il);
  170. // the initializers should be single c
  171. // strings, eg:
  172. //   ["now is"] [" the time" ] [""] [ "I think"]
  173.  
  174. // Declaration of a set of integers
  175. intDeclaration
  176.   -> "int", space...,
  177.       variableList:vl, "{", space?...,
  178.       initializerList:il, "}"           =addTVars(vl,"int","int",il);
  179. // the initializers should be single
  180. // integers, eg:
  181. //   [12] [ 2 ] [18]
  182.  
  183. // Declaration of a set of doubles
  184. doubleDeclaration
  185.   -> "double", space...,
  186.       variableList:vl, "{", space?...,
  187.       initializerList:il, "}"           =addTVars(vl,"double","double&",il);
  188. // the initializers should be single
  189. // floating point numbers, eg:
  190. //   [1.1] [ -2.0 ]
  191.  
  192. // Declaration of a set of FILE pointers
  193. FILEDeclaration
  194.   -> "FILE", space...,
  195.       variableList:vl, "{", space?...,
  196.       initializerList:il, "}"           =addTVars(vl,"FILE *","FILE *",il);
  197. // the initializers should be statements that return a FILE * eg:
  198. //   [ fopen("fname", "r") ]
  199.  
  200. // Declaration of a set of arrays
  201. // of 2 integers (must include
  202. //   "typedef int INTARR2 []"
  203. // in test specification.
  204. intarr2Declaration
  205.   -> "intarr2", space...,
  206.      variableList:vl, "{", space?...,
  207.      initializerList:il, "}"            =addTVars(vl,"INTARR2","INTARR2",il);
  208. // the initializers should each be a list of
  209. // integers in braces, eg:
  210. //   [ { 1, 3} ]
  211.  
  212. // Declaration of a set of Item objects
  213. ItemDeclaration
  214.  -> "Item", space...,
  215.      variableList:vl, "{", space?...,
  216.      initializerList:il, "}"            =addTVars(vl,"Item","Item&",il);
  217. // the initializers should be constructors of Item objects, eg:
  218. // [ Item(1001, 2, 12.38) ]
  219.  
  220. // Declaration of a set of Client objects
  221. ClientDeclaration
  222.  -> "Client", space...,
  223.      variableList:vl, "{", space?...,
  224.      initializerList:il, "}"            =addTVars(vl,"Client","Client&",il);
  225. // the initializers should be constructors of Client objects, eg:
  226. // [ Client(RETAIL) ]
  227.  
  228. // Declaration of a set of Invoice objects
  229. InvoiceDeclaration
  230.  -> "Invoice", space...,
  231.      variableList:vl,